<template lang="">
  <div>
    <header class="header">
      <h1>TodoIt</h1>
      <input
        class="new-todo"
        placeholder="今日任务"
        autofocus
        v-model="todoName"
        @keyup.enter="todoAdd"
        v-myFocus
      />
    </header>
  </div>
</template>
<script>
export default {
  data() {
    return {
      todoName: "",
    };
  },
  methods: {
    // 新增数据
    todoAdd() {
      if (this.todoName.length === 0) {
        return alert("不能为空");
      }
      console.log(this.todoName);
      this.$emit("onAdd", this.todoName);
      this.todoName = "";
    },
  },
};
</script>
<style lang=""></style>
